package mskruch.gps;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Points {
    private Point[] data;

    public Points(Point[] data) {
        super();
        if (data == null || data.length < 1) {
            throw new IllegalArgumentException("At least 1 point required to create " + Points.class.getCanonicalName()
                    + " object");
        }
        this.data = data;
    }

    public Point[] toArray() {
        return data;
    }

    public List<Point> toList() {
        return Arrays.asList(data);
    }

    @Deprecated
    public Point get(int index) {
        return data[index];
    }

    @Deprecated
    public int size() {
        return data.length;
    }
    
    public Points add(Point[] data) {
        // TODO optimize for many calls
        List<Point> list = new ArrayList<Point>();
        list.addAll(Arrays.asList(this.data));
        list.addAll(Arrays.asList(data));
        this.data = list.toArray(new Point[list.size()]);
        return this;
    }

}
